/*** 
 * @_______________#########_______________________ 
 * @______________############_____________________ 
 * @______________#############____________________ 
 * @_____________##__###########___________________ 
 * @____________###__######_#####__________________ 
 * @____________###_#######___####_________________ 
 * @___________###__##########_####________________ 
 * @__________####__###########_####_______________ 
 * @________#####___###########__#####_____________ 
 * @_______######___###_########___#####___________ 
 * @_______#####___###___########___######_________ 
 * @______######___###__###########___######_______ 
 * @_____######___####_##############__######______ 
 * @____#######__#####################_#######_____ 
 * @____#######__##############################____ 
 * @___#######__######_#################_#######___ 
 * @___#######__######_######_#########___######___ 
 * @___#######____##__######___######_____######___ 
 * @___#######________######____#####_____#####____ 
 * @____######________#####_____#####_____####_____ 
 * @_____#####________####______#####_____###______ 
 * @______#####______;###________###______#________ 
 * @________##_______####________####______________ 
 * @
 * @Author: ipk518 18163976442@163.com
 * @Date: 2024-06-19 10:31:14
 * @LastEditors: ipk518 121206530@qq.com
 * @LastEditTime: 2025-09-03 16:20:23
 * @FilePath: /etws-sxk2307/inc/Event.h
 * @Description: 
 * @************佛祖保佑************
 * @Copyright (c) 2024 by etws@quyujiang, All Rights Reserved. 
 */

#ifndef __EVENT_H__
#define __EVENT_H__


#pragma once
#include <queue>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <map>

enum EventType {
    CALI_BEAM,
    WRITE_BEAM_PARAM,
    WRITE_BEAM_LIST,
    WRITE_HARDWARE_TEST,
    WRITE_CONTROL_REG,
    WRITE_DBF_REG,      // 写DBF
    WRITE_DBF_POINT,    // 写DBF波束指向
    WRITE_MANUALCALI_COE,
    WRITE_AUTOCALI_COE,
    WRITE_PHASECODE,    // 写相位码
};

class Event {
public:
    
public:
    void start();

    void stop();

    void addEvent(const EventType eventName, std::function<void()> eventHandler);

    void triggerEvent(EventType event);
private:
    bool m_Running = false;
    std::queue<EventType> eventQueue;
    std::mutex eventMutex;
    std::condition_variable eventCV;
    std::thread eventThread;

    void processEvent(EventType event);
private:
    std::map<EventType, std::function<void()>> events;
};

#endif